package com.acme.bankapp.network;

import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.exceptions.ClientExistsException;
import com.acme.bankapp.util.Utils;

public class AddClientCommand implements Command {

    public AddClientCommand(final Bank bank, final Client client) {
	this.bank = bank;
	this.client = client;
    }

    @Override
    public String execute() {
	try {
	    bank.addClient(client);
	} catch (ClientExistsException e) {
	    return Utils.getErrorMessage(e);
	}
	
	return "Client " + client.getClientSalutation()
		+ " has been successfully added to the bank";
    }

    private Bank bank;
    private Client client;
}
